/**
 * Created by Administrator on 2017/8/30 0030.
 */
var params;
var requestHandler = {
      params: {},
      API_URL: '',
      token: '',
      success: function (res) {
            // success  
      },
      fail: function () {
            // fail  
      },
}

//GET请求  
function GET(requestHandler) {
      request('GET', requestHandler)
}
//POST请求  
function POST(requestHandler) {
      request('POST', requestHandler)
}

function request(method, requestHandler) {
      //注意：可以对params加密等处理  
      var params = requestHandler.params;
      var API_URL = requestHandler.API_URL;
      var header = {
        "Content-Type": "application/x-www-form-urlencoded",
      }
      if(requestHandler.header!=undefined){
        header = requestHandler.header;
      }
      wx.request({
            // url: 'http://192.168.0.110:8080' + API_URL ,
            url: getApp().url + API_URL,
            data: params,
            method: method,
            header:header,
            success: function (res) {
                  //注意：可以对参数解密等处理  
                  // console.log(res, 'aaa')
                  requestHandler.success(res)
            },
            fail: function () {
                  requestHandler.fail()
            },
            complete: function () {
                  // complete  
            }
      })
}

module.exports = {
      GET: GET,
      POST: POST
} 